package markgame2d.engine.mover;

import java.awt.Rectangle;

import markgame2d.engine.interfaces.Moveable;

public class MarkLimitMover implements MarkMover{

	private Moveable moveable;
	private Rectangle limit;
	
	public MarkLimitMover(Moveable moveable, Rectangle limit) {
		this.moveable = moveable;
		this.limit = limit;
	}
	
	public Moveable getMoveable() {
		return moveable;
	}
	public void setMoveable(Moveable moveable) {
		this.moveable = moveable;
	}
	public void move(float time) {
		Rectangle bounds = moveable.getBounds();
		
		if(bounds.x < limit.x){
			moveable.setX(limit.x);
		}else if(bounds.x + bounds.width >= limit.x + limit.width){
			moveable.setX(limit.x + limit.width - bounds.width);
		}
		
		if(bounds.y < limit.y){
			moveable.setY(limit.y);
		}else if(bounds.y + bounds.height >=  limit.y + limit.height){
			moveable.setY(limit.y + limit.height - bounds.height);
		}
	}
	
	
}
